package test.wk.constants;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;

import com.wk.database.MachinesMap;
import com.wk.job.Job;
import com.wk.masterNode.DistrubuteJob;

/***
 * 测试是否可以真的发送到远程计算节点。 
 * @author wkhua
 *
 */

public class DistributeJobClient {
	public static void main(String[] args) {
		
		//初始化job表
		LinkedBlockingQueue<Job> jobsqueue = new LinkedBlockingQueue<>();
		Job job53 = new Job("53", "wk53");
		jobsqueue.add(job53);
		Job job11 = new Job("11", "wk11");
		jobsqueue.add(job11);
	
		//初始化映射表
		Map<String, String> idAndMachine = new HashMap<>();
		MachinesMap machinesMap = new MachinesMap();
		machinesMap.initFromProperties(idAndMachine);
		
		//初始化已分发的任务映射表
		ConcurrentHashMap<String, Job> distributedjobsMap =new ConcurrentHashMap<>();
		
		//初始化分发器
		DistrubuteJob distri = new DistrubuteJob(jobsqueue, idAndMachine, distributedjobsMap);
	//while(!jobsqueue.isEmpty()){
		while(true){
			boolean success =  distri.distributeAJob();
			System.out.println(success);
			Set<String> keys = distributedjobsMap.keySet();
			
			System.out.println(distributedjobsMap.size());
			for(String key :keys){
				System.out.println(key+": "+distributedjobsMap.get(key));
			}
		}
		
		
	}
}
